/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IFormDaftar.java
 *
 * Created on 15 Jun 10, 6:04:41
 */
package clinsoftbeta.GUI;

import clinsoftbeta.database.Database;
import com.mysql.jdbc.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Sidiq Prihatno
 */
public class IFormDaftar extends javax.swing.JInternalFrame {

    int administrasi, obat, total;
    DefaultTableModel tbModel;
    String query = "";
    private Statement st;
    private Database db;
    private ResultSet rs;
    String modeOperasi = "";

    /** Creates new form IFormDaftar */
    public IFormDaftar() {
        initComponents();
        txtNama.setDocument(new CumaHuruf());
        setVisible(true);
        db = new Database();
        db.koneksiDatabase();
        isikanTabel();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        bg1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        txtObat = new javax.swing.JTextField();
        txtAdministrasi = new javax.swing.JTextField();
        txtTotal = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtKodePasien = new javax.swing.JTextField();
        txtNama = new javax.swing.JTextField();
        txtALamat = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        taKeluhan = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtTanggal = new javax.swing.JTextField();
        btnCari = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        txtNoDaftar = new javax.swing.JTextField();
        cmbJenisID = new javax.swing.JComboBox();
        txtJenisKelamin = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        btnHapus = new javax.swing.JButton();
        btnBersih = new javax.swing.JButton();
        btnSimpan = new javax.swing.JButton();
        btnBatal = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbDaftar = new javax.swing.JTable();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Form Pendaftaran");
        setAutoscrolls(true);

        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("Jenis ID");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 5;
        gridBagConstraints.insets = new java.awt.Insets(9, 9, 9, 9);
        jPanel2.add(jLabel1, gridBagConstraints);

        jLabel2.setText("Administrasi");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(jLabel2, gridBagConstraints);

        jLabel3.setText("Obat");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(jLabel3, gridBagConstraints);

        jLabel13.setText("Total");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(jLabel13, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(txtObat, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(txtAdministrasi, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(txtTotal, gridBagConstraints);

        jLabel4.setText("Kode Pasien");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(9, 9, 9, 9);
        jPanel2.add(jLabel4, gridBagConstraints);

        jLabel5.setText("Nama Pasien");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(9, 8, 9, 8);
        jPanel2.add(jLabel5, gridBagConstraints);

        jLabel6.setText("Alamat");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(9, 8, 9, 8);
        jPanel2.add(jLabel6, gridBagConstraints);

        jLabel7.setText("Keluhan");
        jLabel7.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(9, 8, 9, 8);
        jPanel2.add(jLabel7, gridBagConstraints);

        txtKodePasien.setPreferredSize(new java.awt.Dimension(100, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 11);
        jPanel2.add(txtKodePasien, gridBagConstraints);

        txtNama.setPreferredSize(new java.awt.Dimension(50, 20));
        txtNama.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNamaActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(txtNama, gridBagConstraints);

        txtALamat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtALamatActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(txtALamat, gridBagConstraints);

        taKeluhan.setColumns(20);
        taKeluhan.setRows(5);
        jScrollPane1.setViewportView(taKeluhan);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 11, 10);
        jPanel2.add(jScrollPane1, gridBagConstraints);

        jLabel8.setText("Jenis Kelamin");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(9, 9, 9, 9);
        jPanel2.add(jLabel8, gridBagConstraints);

        jLabel9.setText("Tanggal");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(19, 10, 19, 10);
        jPanel2.add(jLabel9, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(20, 10, 20, 12);
        jPanel2.add(txtTanggal, gridBagConstraints);

        btnCari.setText("Cari");
        btnCari.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 14);
        jPanel2.add(btnCari, gridBagConstraints);

        jLabel10.setText("No");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 3;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(21, 7, 21, 1);
        jPanel2.add(jLabel10, gridBagConstraints);

        txtNoDaftar.setPreferredSize(new java.awt.Dimension(40, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 2;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(21, 0, 21, 10);
        jPanel2.add(txtNoDaftar, gridBagConstraints);

        cmbJenisID.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Pilih --", "ASKES", "JPKM", "UMUM" }));
        cmbJenisID.setPreferredSize(new java.awt.Dimension(150, 20));
        cmbJenisID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbJenisIDActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(cmbJenisID, gridBagConstraints);

        txtJenisKelamin.setPreferredSize(new java.awt.Dimension(50, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(9, 10, 9, 10);
        jPanel2.add(txtJenisKelamin, gridBagConstraints);

        jPanel1.add(jPanel2, java.awt.BorderLayout.PAGE_START);

        jPanel7.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 20, 20));

        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });
        jPanel7.add(btnHapus);

        btnBersih.setText("Bersih");
        btnBersih.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBersihActionPerformed(evt);
            }
        });
        jPanel7.add(btnBersih);

        btnSimpan.setText("Simpan");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });
        jPanel7.add(btnSimpan);

        btnBatal.setText("Batal");
        btnBatal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBatalActionPerformed(evt);
            }
        });
        jPanel7.add(btnBatal);

        jPanel1.add(jPanel7, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.WEST);

        jPanel3.setLayout(new java.awt.BorderLayout());

        jScrollPane2.setPreferredSize(new java.awt.Dimension(379, 100));

        tbDaftar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Tanggal", "No. Daftar", "Jenis ID", "Kode Pasien", "Nama", "Alamat", "Jenis Kelamin", "Keluhan", "Administrasi", "Obat", "Total"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tbDaftar.setPreferredSize(new java.awt.Dimension(300, 64));
        tbDaftar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbDaftarMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tbDaftar);

        jPanel3.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtALamatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtALamatActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtALamatActionPerformed

    private void btnBersihActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBersihActionPerformed
        // TODO add your handling code here:
        txtJenisKelamin.setText("");
        cmbJenisID.setSelectedIndex(0);
        bg1.clearSelection();
        txtTanggal.setText("");
        txtNoDaftar.setText("");
        txtALamat.setText("");
        txtKodePasien.setText("");
        txtNama.setText("");
        txtAdministrasi.setText("");
        txtObat.setText("");
        txtTotal.setText("");
        taKeluhan.setText("");
}//GEN-LAST:event_btnBersihActionPerformed
    private void isikanTabel() {
        String[] tbHeader = {"No. Pendaftaran", "Tanggal", "Jenis ID", "Kode Pasien", "Nama Pasien", "Jenis Kelamin", "Alamat", "Keluhan"};
        tbModel = new DefaultTableModel(null, tbHeader);
//        kosongkanTabel();
        try {
            query = "Select no_daftar, tanggal, jenis_id, kode_pasien, nama_pasien, jenis_kelamin, alamat, keluhan, administrasi, obat, total from pendaftaran";
            st = (Statement) db.koneksi.createStatement();
            rs = st.executeQuery(query);
            while (rs.next()) {
                String[] tbData = {rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11)};
                tbModel.addRow(tbData);
            }
        } catch (SQLException se) {
            se.printStackTrace();
            //System.exit(0);
        }
        tbDaftar.setModel(tbModel);
        if (tbDaftar.getRowCount() > 0) {
            tbDaftar.addRowSelectionInterval(0, 0);
            //      tampilkanDiText();
//            aktifText(false);
//            AktifSimpan(false);
        } else {
            //btnBaruActionPerformed(null);
        }
    }
    private void txtNamaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNamaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNamaActionPerformed

    private void cmbJenisIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbJenisIDActionPerformed
        // TODO add your handling code here:
        if (cmbJenisID.getSelectedItem().equals("ASKES")) {
            administrasi = 500;
            obat = 500;
            txtAdministrasi.setText(String.valueOf(administrasi));
            txtObat.setText(String.valueOf(obat));
            total = administrasi + obat;
            txtTotal.setText(String.valueOf(total));
        }
        if (cmbJenisID.getSelectedItem().equals("JPKM")) {
            administrasi = 0;
            obat = 0;
            txtAdministrasi.setText(String.valueOf(administrasi));
            txtObat.setText(String.valueOf(obat));
            total = administrasi + obat;
            txtTotal.setText(String.valueOf(total));
        }
        if (cmbJenisID.getSelectedItem().equals("UMUM")) {
            administrasi = 2000;
            obat = 8000;
            txtAdministrasi.setText(String.valueOf(administrasi));
            txtObat.setText(String.valueOf(obat));
            total = administrasi + obat;
            txtTotal.setText(String.valueOf(total));
        }
    }//GEN-LAST:event_cmbJenisIDActionPerformed

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanActionPerformed
        // TODO add your handling code here:
        if (txtNoDaftar.getText().trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "Data ada yang masih kosong");

        }
            try {
                query = "INSERT INTO pendaftaran VALUES('" + txtNoDaftar.getText() + "','" + txtTanggal.getText() + "','" + cmbJenisID.getSelectedItem() + "','" + txtKodePasien.getText() + "','" + txtNama.getText() + "','" + txtJenisKelamin.getText() + "','"
                        + txtALamat.getText() + "','" + taKeluhan.getText() + "','" + txtAdministrasi.getText() + "','" + txtObat.getText() + "','" + txtTotal.getText() + "')";
                PreparedStatement presttmt = db.koneksi.prepareStatement(query);
                presttmt.executeUpdate(query);
                JOptionPane.showMessageDialog(null, "Data berhasil disimpan");
                //dispose();
                //tbDaftar.revalidate();
            } catch (SQLException se) {
                JOptionPane.showMessageDialog(null,
                        "Terjadi kesalahan input data! error :" + se,
                        "Kesalahan", JOptionPane.ERROR_MESSAGE);
               // dispose();
            }
        
    }//GEN-LAST:event_btnSimpanActionPerformed

    private void btnCariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariActionPerformed
        //  TODO add your handling code here:
     /*  int row = tbModel.getRowCount();
        for (int i = 0; i
        < row; i++) {
        tbModel.removeRow(0);
        }*/
        if (txtKodePasien.getText().trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "Data masih kosong");
        }
        try {
            query = "Select kode_pasien, nama_pasien,  jenis_kelamin, alamat from pasien where kode_pasien like '%" + txtKodePasien.getText() + "%'";
            st = (Statement) db.koneksi.createStatement();
            rs = st.executeQuery(query);

            while (rs.next()) {
               
                txtKodePasien.setText(rs.getString(1));
                txtNama.setText(rs.getString(2));
                txtJenisKelamin.setText(rs.getString(3));
                txtALamat.setText(rs.getString(4));

            }
        } catch (SQLException se) {
            se.printStackTrace();

            //System.exit(0);
        }

    }//GEN-LAST:event_btnCariActionPerformed

    private void btnBatalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBatalActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnBatalActionPerformed

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapusActionPerformed
        // TODO add your handling code here:
        if (txtKodePasien.getText().trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "Data ada yang masih kosong");
        }
        try {
            query = "delete from pendaftaran where no_daftar ='" + txtNoDaftar.getText() + "'";
            PreparedStatement presttmt = db.koneksi.prepareStatement(query);
            presttmt.executeUpdate(query);
            JOptionPane.showMessageDialog(null, "Data berhasil di hapus");
            //dispose();
            //tbDaftar.revalidate();
        } catch (SQLException se) {
            JOptionPane.showMessageDialog(null,
                    "Terjadi kesalahan hapus data! error :" + se,
                    "Kesalahan", JOptionPane.ERROR_MESSAGE);
            dispose();
        }

    }//GEN-LAST:event_btnHapusActionPerformed

    private void tbDaftarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbDaftarMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 1) {
            Tampil();
        }
    }
    int row = 0;

    public void Tampil() {
        row = tbDaftar.getSelectedRow();
        txtNoDaftar.setText(tbDaftar.getValueAt(row, 0).toString());
        txtTanggal.setText(tbDaftar.getValueAt(row, 1).toString());
        cmbJenisID.setSelectedItem(tbDaftar.getValueAt(row, 2).toString());
        txtKodePasien.setText(tbDaftar.getValueAt(row, 3).toString());
        txtNama.setText(tbDaftar.getValueAt(row, 4).toString());
        txtJenisKelamin.setText(tbDaftar.getValueAt(row, 5).toString());
        txtALamat.setText(tbDaftar.getValueAt(row, 6).toString());
        taKeluhan.setText(tbDaftar.getValueAt(row, 7).toString());
        txtAdministrasi.setText(tbDaftar.getValueAt(row, 8).toString());
        txtObat.setText(tbDaftar.getValueAt(row, 9).toString());
        txtTotal.setText(tbDaftar.getValueAt(row, 10).toString());
    }//GEN-LAST:event_tbDaftarMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bg1;
    private javax.swing.JButton btnBatal;
    private javax.swing.JButton btnBersih;
    private javax.swing.JButton btnCari;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnSimpan;
    private javax.swing.JComboBox cmbJenisID;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea taKeluhan;
    private javax.swing.JTable tbDaftar;
    private javax.swing.JTextField txtALamat;
    private javax.swing.JTextField txtAdministrasi;
    private javax.swing.JTextField txtJenisKelamin;
    private javax.swing.JTextField txtKodePasien;
    private javax.swing.JTextField txtNama;
    private javax.swing.JTextField txtNoDaftar;
    private javax.swing.JTextField txtObat;
    private javax.swing.JTextField txtTanggal;
    private javax.swing.JTextField txtTotal;
    // End of variables declaration//GEN-END:variables
}
